Asp2.0下Login.Aspx页面和VS2005登陆控件冲突问题

有句老话说,常在河边走,哪能不湿鞋,呵呵,今天终于让我遇到了。

VS2005项目中,若有个页面文件是Login.aspx,即类名为 Login,这样就会和VS2005中自带的登陆控件的类名起冲突,在本地VS项目文件下调试或浏览一切都没有问题,若是选择发布的话,那浏览到这个文件 的时候就会出错。

错误信息如下所示:

((Login)(this)).AppRelativeVirtualPath = "~/login.aspx";

它的意思是说需要把Login.aspx这个文件进行转化,转化成Login登陆控件的时候,那当然会 出错拉,这样都还不错,那简直是奇迹了。

翻遍了CSDN也没有找到类似问题,呵呵,可能是还没有人遇到过吧?或者是遇到了,但就只是把文 件名一改,能运行就算了解决问题了。

下面说明下问题产生的原因和解决办法:
1、必须是在2005下,2.0 Framework下才会有这个问题,2003,1.1下是肯定不会有这个问题的,因为Login登陆控件是VS2005才加的东东,很多人说比较实用, 不过我是不怎么喜欢。
2、项目文件中,文件名必须是Login.aspx或者其他的登陆控件的类名和VS2005中带的控件类名相同了才可能会出 这个问题,所以这里建议大家,文件命名的时候,最好不要和VS2005的控件名一样了,否则出这出那的问题,白白浪费了很多调试的时间,因为这样的问题, 在VS下面,本地浏览是没有错误的,只有Publish下才会有问题。

解决办法:
If you have used a Page that effectively uses a codebehind classname that is the same as say the Login control, that is Login, e.g. your page was called Login.aspx, then when you pre-compile (publish) the web site as an updateable web site, the aspx is retained and tries to compile against a type called Login in the code behind. It does not resolve to be that in the codebehind assembly Try using a classname for your codebehind and defined in the inherits that does not clash with a type in System.Web, e.g. LoginPage, or qualify the class and therefore the inherits statement with a namespace, e.g.

建议采用操作:
<%@ page ... inherits="theNs.Login" %>或者不要使用Login.aspx(Login为类名) 文件名,其中theNs为命名空间名称.
有兴趣的可以看看这,内容比较详细:
http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic13767.aspx





I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web server. I am able to log in. However after publishing the page to my local IIS, it results in the below error. This error is occurring on the Visual Studio.Net 2k5 release version, but did not occur on the beta 2, same code.

A point of interest, is that I uninstalled IIS, then re-installed it after a recent system rebuild (which I did to completely remove the beta), and I reinstalled asp.net to IIS afterwards.

First the html :
***************************************************************************************************
***************************************************************************************************
<%@ Page Language="C#" MasterPageFile="~/default.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" Title="Login" %>





***************************************************************************************************
***************************************************************************************************
Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1310
Date: 11/7/2005
Time: 10:43:16 AM
User: N/A
Computer: DEVPC01
Description:

Event code: 3007
Event message: A compilation error has occurred.
Event time: 11/7/2005 10:43:16 AM
Event time (UTC): 11/7/2005 4:43:16 PM
Event ID: 6c82372492fa42dbbbd4a0f5b794ed8d
Event sequence: 40
Event occurrence: 7
Event detail code: 0

Exception information: Exception type: HttpCompileException
Exception message: c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/deleted/3ee2c232/4383868/App_Web_login.aspx.cdcab7d2.pfd6ysg8.0.cs(118):
error CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Request information:
User host address: 127.0.0.1
User:
Is authenticated: False
Authentication Type:
Thread account name: DEVPC01/ASPNET

Thread information:
Thread ID: 1
Thread account name: DEVPC01/ASPNET
Is impersonating: False
Stack trace: at System.Web.Compilation.AssemblyBuilder.Compile()

at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



Simply using a different name for the page is not enough.
Here is the solution I found on Microsoft's lab website:

If you have used a Page that effectively uses a codebehind classname
that is the same as say the Login control, that is Login, e.g. your
page was called Login.aspx, then when you pre-compile (publish) the web
site as an updateable web site, the aspx is retained and tries to
compile against a type called Login in the code behind. It does not
resolve to be that in the codebehind assembly

Try using a classname for your codebehind and defined in the inherits
that does not clash with a type in System.Web, e.g. LoginPage, or
qualify the class and therefore the inherits statement with a
namespace, e.g.

<%@ page ... inherits="theNs.Login" %.

namespace theNs { public partial class Login : System.Web.UI.Page { ..
} }

Now... going to the next challenge... :)

Take care you all!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值