ASP.NET MVC issue with configuration of forms authentication section

前端 未结 8 559
孤独总比滥情好
孤独总比滥情好 2020-12-15 05:36

I have an ASP.NET MVC 3 Beta application running on IIS. In my web.config I defined following section responsible for forms authentication:

<         


        
相关标签:
8条回答
  • The tilde (~) means "the root of my web site" so you don't have to keep using .. or \ to step up and down the web site structure. However, from an IIS perspective you web application may have an additional layer of directory structure which is being reflected when you request the LoginUrl programmatically. I'm unsure as to why you want to retrieve the LoginUrl, the normal state of affairs would have IIS redirect the user to the LoginUrl automatically any time they try to access a page that they are not authenticated for.

    0 讨论(0)
  • 2020-12-15 05:49

    Updated answer for MVC 4, heavily borrowed from this page and Request redirect to /Account/Login?ReturnUrl=%2f since MVC 3 install on server

    <appSettings>
       ...
       <add key="PreserveLoginUrl" value="true" />
    </appSettings>
    
    ...
    
    <authentication mode="Forms">
          <forms loginUrl="~/Account/LogOn" timeout="43200" /> <!--43,200 in minutes - 30 days-->
    </authentication>
    
    0 讨论(0)
  • 2020-12-15 05:50

    If you have access to IIS, then append a new application and enable ASP.NET "integrated pipelining" in application pool section by double clicking it.

    If your hosting provider does not grant you access to IIS, then login to the control panel.

    • Go to websites, under the management tab- enable ASP.NET integrated pipe lining.
    • Set your application as a virtual directory (It worked for me)
    0 讨论(0)
  • 2020-12-15 05:55

    Put the following in appSettings:

    <add key="loginUrl" value="~/Account/LogOn" />
    

    You could empty loginUrl from Form Authentication configuration.

    0 讨论(0)
  • 2020-12-15 05:56

    So the simple solution was to remove WebMatrix.*.dll from Bin folder in web project. I have done this for my asp.net project since it was redirecting my login to mvc style url.

    0 讨论(0)
  • 2020-12-15 06:00

    I think the server has trouble deciding what ~ means in this case, try giving a more direct url to the login page, such as /Account/LogOn.

    Maybe you'll find something useful here http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx

    0 讨论(0)
提交回复
热议问题