问题
I've read through a few other threads on here, though none of them really explain how to resolve my issue.
I have a web application with the following page (code behind)
namespace Company.Web.UI.Content
{
public partial class Home_LoggedOut : Company.Web.UI.CompanyPage
{
string _myType = this.GetType().FullName.Replace(".", "_");
}
}
Now I'd have hoped to get something like:
Company_Web_UI_Content_Home_LoggedOut
but instead I'm getting:
ASP_home_loggedout_aspx
I'm clearly missing something about class structures and how they work, so I'd like to understand that, but is there any way for me to get the fully qualified namespace + class name in this scenario?
Ideally, I'd like to include this in the base type (Company.Web.UI.CompanyPage) so that I can do something with it, so anything that is suggested would have to work at that level too.
Hope I'm not completely missing the point here (well, I probably am, but hopefully there is a way around it!)
Cheers, Terry
Update: Answer came in as:
string _myType = this.GetType().BaseType.FullName.Replace(".", "_");
thanks guys :)
回答1:
When you have a page with a code behind you actually have two classes. One is from the code behind which gets inherited by the class for the page. That's why you get that name. Try this and see if it works:
string _myType = this.GetType().BaseType.FullName.Replace(".", "_");
回答2:
ASP.NET engine generates a class based on your ASPX markup and this class is inherited from Company.Web.UI.Content.Home_LoggedOut. You can try:
this.GetType().BaseType.FullName.Replace(".", "_")
Honestly, I've never tried it, but theoretically it should work =)
来源:https://stackoverflow.com/questions/1559312/asp-net-gettype-and-fully-qualified-class-names