asp.net 3.5升级到4.0 IIS6 ReturnURL问题
我最近将一个项目从 3.5 升级到 4.0,一切都很顺利,除了 ReturnUrl 没有做它以前做的事情。项目结构:
所有项目都是asp.net 4.0:
1.(根):http://example.com
2.(项目1)http://example.com/Project1
3. (MyProject) http://example.com/MyProject <- 虚拟目录。这个项目有问题。
这是我的 web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
...
</configSections>
<!--System.net Mail setup-->
<system.net>
<mailSettings>
<smtp from="support@localhost">
<network host="localhost" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
<appSettings>
...
<add key="loginUrl" value="Login.aspx" />
<add key="defaultUrl" value="Home.aspx" />
</appSettings>
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnetdb_test;Integrated Security=True" providerName="System.Data.SqlClient"/>
...
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
...
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>
<customErrors mode="Off"/>
<!--<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
<error statusCode="403" redirect="PageNotFound.aspx"/>
<error statusCode="404" redirect="PageNotFound.aspx"/>
</customErrors>-->
<pages enableSessionState="true" validateRequest="false" enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
...
</controls>
</pages>
<httpHandlers>
...
</httpHandlers>
<httpModules>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
...
</httpModules>
<httpRuntime maxRequestLength="458292"/>
<authentication mode="Forms">
<!--<forms loginUrl="~/Login.aspx" defaultUrl="~/Home.aspx" protection="All" timeout="60" name=".ASPXFORMSAUTH" requireSSL="false" slidingExpiration="true" cookieless="UseCookies" enableCrossAppRedirects="false"/>-->
<forms loginUrl="Login.aspx" protection="All" timeout="60" name=".ASPXFORMSAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Home.aspx" cookieless="UseCookies" enableCrossAppRedirects="false" />
</authentication>
<authorization>
<allow roles="Admin"/>
<allow roles="Student"/>
<allow roles="Test"/>
<deny users="*"/>
<deny users="?"/>
</authorization>
<machineKey validationKey="..." decryptionKey="..." validation="SHA1"/>
<membership defaultProvider="MembershipProvider">
<providers>
...
</providers>
</membership>
<roleManager enabled="true" defaultProvider="RoleManagerSqlProvider">
<providers>
...
</providers>
</roleManager>
<httpCookies httpOnlyCookies="true"/>
<sessionState cookieless="AutoDetect"/>
<trace enabled="false"/>
</system.web>
<location path="Home.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="Login.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="Logout.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="AJAXServices">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="SignIn.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="ResetPassword.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="About.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="ErrorPage.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="PageNotFound.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="Assets">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
<handlers>
...
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</location>
</configuration>
唯一有帮助的临时修复是 Global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.AppRelativeCurrentExecutionFilePath == "~/")
HttpContext.Current.RewritePath("Home.aspx");
}
然而,如果我导航到 http://example.com/MyProject 它会失败,但如果我这样做: http://example.com/MyProject/ (添加了一个 /)它可以工作。 defaultUrl 不是应该重定向到主应用程序吗?为什么 returnUrl 指向 http://example.com/MyProject/Login.aspx?ReturnUrl=%2fMyProject %2f
我已经在谷歌甚至这个网站上搜索了无数的解决方案,但似乎没有一个能帮我解决这个问题。可能是由于该项目位于其他项目的子目录中并且 web.config 存在冲突。
顺便说一句,在 IIS 的身份验证方法中,选中了“启用匿名访问”,没有检查其他任何内容。
我不知道还有什么可能会导致这个问题。我尝试将 Home.aspx 设为主页或 Login.aspx 并不重要。
附加信息:
C:\WINDOWS\system32>cscript IisExt.vbs /ListFile
Status / Extension Path
------------------------
0 C:\WINDOWS\system32\inetsrv\httpodbc.dll
1 C:\WINDOWS\system32\inetsrv\ssinc.dll
1 C:\WINDOWS\system32\inetsrv\asp.dll
1 C:\ColdFusion9\runtime\lib\wsconfig\jrun_iis6.dll
1 C:\ColdFusion9\runtime\lib\wsconfig\1\jrun_iis6_wildcard.dll
0 *.exe
0 C:\WINDOWS\system32\inetsrv\httpext.dll
0 *.dll
1 c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
1 C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll
另外:
C:\WINDOWS\microsoft.net\Framework64\v4.0.30319>aspnet_regiis -lk
W3SVC/ 4.0.30319.0
W3SVC/1971902459/root/ 4.0.30319.0
W3SVC/1971902459/root/Project1/ 4.0.30319.0
W3SVC/1971902459/root/MyProject/ 4.0.30319.0
W3SVC/53091907/root/ 4.0.30319.0
I have recently upgraded a project from 3.5 to 4.0 everything went great except the ReturnUrl is not doing what it use to. Structure of the project:
All projects are asp.net 4.0:
1. (root): http://example.com
2. (Project1) http://example.com/Project1
3. (MyProject) http://example.com/MyProject <- Virtual Directory. This project is having issues.
Here is my web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
...
</configSections>
<!--System.net Mail setup-->
<system.net>
<mailSettings>
<smtp from="support@localhost">
<network host="localhost" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
<appSettings>
...
<add key="loginUrl" value="Login.aspx" />
<add key="defaultUrl" value="Home.aspx" />
</appSettings>
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnetdb_test;Integrated Security=True" providerName="System.Data.SqlClient"/>
...
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
...
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>
<customErrors mode="Off"/>
<!--<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
<error statusCode="403" redirect="PageNotFound.aspx"/>
<error statusCode="404" redirect="PageNotFound.aspx"/>
</customErrors>-->
<pages enableSessionState="true" validateRequest="false" enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
...
</controls>
</pages>
<httpHandlers>
...
</httpHandlers>
<httpModules>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
...
</httpModules>
<httpRuntime maxRequestLength="458292"/>
<authentication mode="Forms">
<!--<forms loginUrl="~/Login.aspx" defaultUrl="~/Home.aspx" protection="All" timeout="60" name=".ASPXFORMSAUTH" requireSSL="false" slidingExpiration="true" cookieless="UseCookies" enableCrossAppRedirects="false"/>-->
<forms loginUrl="Login.aspx" protection="All" timeout="60" name=".ASPXFORMSAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Home.aspx" cookieless="UseCookies" enableCrossAppRedirects="false" />
</authentication>
<authorization>
<allow roles="Admin"/>
<allow roles="Student"/>
<allow roles="Test"/>
<deny users="*"/>
<deny users="?"/>
</authorization>
<machineKey validationKey="..." decryptionKey="..." validation="SHA1"/>
<membership defaultProvider="MembershipProvider">
<providers>
...
</providers>
</membership>
<roleManager enabled="true" defaultProvider="RoleManagerSqlProvider">
<providers>
...
</providers>
</roleManager>
<httpCookies httpOnlyCookies="true"/>
<sessionState cookieless="AutoDetect"/>
<trace enabled="false"/>
</system.web>
<location path="Home.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="Login.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="Logout.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="AJAXServices">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="SignIn.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="ResetPassword.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="About.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="ErrorPage.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="PageNotFound.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="Assets">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
<handlers>
...
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</location>
</configuration>
The only temp fix that does help is the Global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.AppRelativeCurrentExecutionFilePath == "~/")
HttpContext.Current.RewritePath("Home.aspx");
}
Yet with IE 8/9 if I navigate to http://example.com/MyProject it fails but if I do this:
http://example.com/MyProject/ (added a /) it works. Isn't the defaultUrl suppose to redirect to the main app? And why is the returnUrl pointing to
http://example.com/MyProject/Login.aspx?ReturnUrl=%2fMyProject%2f
I have searched google and even this site with countless solutions but none seem to resolve it for me. Perhaps due to this project being in a sub directory of other projects and having a conflict of web.config.
By the way in the Authentication Methods in IIS Enable anonymous access is checked and nothing else is checked.
I don't know what else there might be that is throwing this off. I have tried to make Home.aspx the main page or Login.aspx doesn't matter.
Additional info:
C:\WINDOWS\system32>cscript IisExt.vbs /ListFile
Status / Extension Path
------------------------
0 C:\WINDOWS\system32\inetsrv\httpodbc.dll
1 C:\WINDOWS\system32\inetsrv\ssinc.dll
1 C:\WINDOWS\system32\inetsrv\asp.dll
1 C:\ColdFusion9\runtime\lib\wsconfig\jrun_iis6.dll
1 C:\ColdFusion9\runtime\lib\wsconfig\1\jrun_iis6_wildcard.dll
0 *.exe
0 C:\WINDOWS\system32\inetsrv\httpext.dll
0 *.dll
1 c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
1 C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll
Also:
C:\WINDOWS\microsoft.net\Framework64\v4.0.30319>aspnet_regiis -lk
W3SVC/ 4.0.30319.0
W3SVC/1971902459/root/ 4.0.30319.0
W3SVC/1971902459/root/Project1/ 4.0.30319.0
W3SVC/1971902459/root/MyProject/ 4.0.30319.0
W3SVC/53091907/root/ 4.0.30319.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是想检查您是否已完全安装 .Net 4.0。与 IIS6 一样,.Net 4.0 可能会出现一些奇怪的错误。
即使您已安装它并在 IIS 中将其设置为正确的应用程序池,开箱即用后它仍然无法工作。
使用以下指南确保 .Net 4.0 的 .dll 已注册,否则您最终将得到一个部分工作的应用程序。
http://johan.driessen .se/posts/getting-an-asp.net-4-application-to-work-on-iis6
Just want to check that you have .Net 4.0 installed fully. As on IIS6 there can be some strange errors with .Net 4.0.
Even though you have installed it and set it up in IIS as the right app pool, out of the box it still wont work.
Use the following guide to make sure that the .dll for .Net 4.0 is registered, otherwise you will end up with a partial working app.
http://johan.driessen.se/posts/getting-an-asp.net-4-application-to-work-on-iis6
不确定是否在配置中设置默认 URL,以前从未尝试过。我们始终在应用程序的 IIS 属性中设置它。也许检查一下?
您可以通过以下方式进行检查:
右键单击 IIS 管理器中的应用程序,单击属性,单击“文档”选项卡,选中“启用默认内容页面”复选框,并确保列表框中包含正确的页面。
Not sure about setting the default URL in the config, never tried that before. We always set it in the IIS properties for the app. Maybe check that?
You can check this by:
Right click the app in IIS manager, click properties, click the "Documents" tab, check the "Enable default content page" checkbox, and make sure the correct page is in the list box.
我想 ASP.NET 4 中引入的无扩展 url 功能会导致一些问题。
Thomas Marquardt 有一篇关于禁用此功能的博客文章 此处。
尝试一下,希望你的烦恼会消失。
I imagine the extensionless url feature introduced in ASP.NET 4 is causing some issues.
Thomas Marquardt has a blog post on disabling this feature here.
Give this a try and hopefully your woes will be gone.