I got an ASP.NET web application and as usual I published it, but it is not working. The error is:
Endpoint not found. Please see the service help page for constructing valid requests to the service.
A default.aspx file is working fine, but when I publish the website it is not working. Note that there are .svc files in the root directory, maybe the issue is related to those.
it is solved,
The reason is, I forgot code in Global.asax file , after I delete the following code it works fine,
Thanks!
protected void Application_Start(object sender, EventArgs e)
{
// RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(DataManager)));
}
Related
I have a web application hosted by an Azure App service. It has worked fine for years but suddenly I get an Exception when i try to enter the Account/login action:
-->"XmlException: Root element is missing" + "CryptographicException: An error occurred while trying to encrypt the provided data.".
If i got to Home/About action (which have [AllowAnonymous] attribute) that page works fine.
But if i try to enter a page within the Account controller which have the [AllowAnonymous] attribute. That also throw the same Exception. So I am guessing the Exception occur in the constructor for the Account controller. See below.
I have not made any updates to the page in months and it has worked fine until now.
If I run the application locally on my PC (connected to the same database on azure) it works fine.
As I understand Azure have recently made updates to their portal.
My guess is that the cause of the error is related to that.
Does anyone know how to solve this?
public AccountController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
IEmailSender emailSender,
ILogger<AccountController> logger,
ApplicationDbContext context)
{
_userManager = userManager;
_signInManager = signInManager;
_emailSender = emailSender;
_logger = logger;
_context = context;
}
Ok so I found the problem myself. After digging in to Debug snapshots available in Azure i got a hint that the directory where the app was trying to get the xml causing the exception was "D:\home\ASP.NET\DataProtection-Keys". When I analysed the content of that directory I saw that one xml-file was empty. I Deleted that file. And that solved the problem.
Having an App in Azure app services. A .NET web project.
Running the line:
System.IO.File.ReadAllText("D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")
will throw an exception
The system cannot find the file specified.
you can see the file is there and believe me it is not miss spelling, locally it works fine and fail when deployed.
The code you mentioned need to be changed as following:
System.IO.File.ReadAllText(#"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings")
You mentioned that will throw not found exception, it is very odd. The code should work in the azure website if the file is existing.
The system cannot find the file specified.
It seems that expection is caused by other codes. We also could remote debug the WebApp with Vistual Studio and we could get the more detail info about exception.
We also could add a sample test aspx page to test it. The following is my test steps.
1.Create a .net Web project and the index.aspx page
2.Add the code to index.aspx.CS file and index.aspx file
protected void Page_Load(object sender, EventArgs e)
{
var file= System.IO.File.ReadAllText(#"D:\home\site\wwwroot\Prod-Enterprise-Test-6-26-2016-credentials.publishsettings");
Label1.Text = file;
}
index.aspx
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
3.Publish the Website to azure environment and add the setting file with content "Test info" via the Kudu tool
Visit the index page from the browser and check that it works correctly.
Well, the problem was in a different location in the code.
The code as published works fine.
I crated area/modular MVC5 application according to this tutorial:
This
it worked perfectly on local. but i got 404 error, when i deployed project on iis and clicked on specified area link.
and i didn't find any solution for that.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Sale
and this is my action links which are perfectly working on local run:
#Html.ActionLink("Sale","Index","Sale",new { Area="Sale"},null)
edited:
public class SaleAreaRegistration:AreaRegistration
{
public override string AreaName
{
get
{
return "Sale";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Sale_default",
"Sale/{controller}/{action}/{id}",
new { controller = "Sale", action = "Index", id = UrlParameter.Optional },
new string[] { "MVCPluggableDemo.Controllers" }
);
}
}
attention: according to the tutorial which i said in first line. i created my module project in another virtual project in solution(the real path is in area folder of main project like"~/ProjectName/Areas/"). but i think the publisher does't understand it...because i don't see any of my module views in deployed path.
its better to completing my help request by this obvious question:
How to deploy MVC project include areas, and the modules which are in areas folder?
Its simply obvious:
Check your page directory. The server cannot locate your the file,
it maybe in different folder.
Also try to Check this.
the main Reason of my problem was this:
VisualStudio doesn't include my Area folder, in publish path..why? i don't know
Solution: no solution yet!..but i added my module dll inside bin folder manually. and created my areas folder and his modules projects solution(dlls' are not not necessary) in main published solution, manually to ..
finally it worked, but i dont thing is the standard solution
I'm having some troubles in my production environment, I found some clues that can lead to an IIS reset, but I'm not sure.
How and where can I find if there was an IIS reset in the past?
Edit:
Regarding the future resets the Kevin's solutions is ok and I have successfully used it.
You could create a Global.asax file on your ASP .Net application. Then you can hook into the application start and stop events with the following methods:
public void Application_Start(object sender, EventArgs e)
{
// log iis started
}
public void Application_End(object sender, EventArgs e)
{
// log iis stopped
}
All you have to do is declare these methods in your global.asax file, ASP .Net will automatically call them when your application is started/stopped. You can then do any logging code you need inside these methods.
I have a web role on azure and I would like to force a Application_Start without waiting for the first request.
I managed to set the "Start Automatically" property to true on my site
AutoStart a WCF on Azure WebRole
But the Application_Start is not called until the first request comes.
I don't know exactly if I am missing something important here. The server is a W2008 R2 and the IIS version is 7.5
Thanks!
SOLUTION
I put the solution code here. I hope will help someone. I just added a WebRole.cs and just put that code to perform a ping every 30 seconds. Please netice I'm browsing Service.svc because this is my endpoint, your endpoint could be another one. Notice I'm asking for "Endpoint1". If you have more than one endpoints, you should review that line.
public class WebRole : RoleEntryPoint
{
public override void Run()
{
var localuri = new Uri( string.Format( "http://{0}/Service.svc", RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint ) );
while (true)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(localuri);
request.Method = "GET";
var response = request.GetResponse();
}
catch { }
System.Threading.Thread.Sleep(30000);
}
}
public override bool OnStart()
{
return base.OnStart();
}
}
The IIS will only start when the first request arrives. The workaround is to send an HTTP request to the same VM from within OnStart or your RoleEntryPoint descendant - that's easy using WebRequest or equivalent class.
Jordi, I've recently experienced the same issue.
Based on my test Application_Start() is called ONLY when the 1st request ISS for the WebApp. (if you try to start VS in Debug without it open any page (see options in proj/debug), you will see that Application_Start() won't be called also if you don't run the WebApp in Azure)
I suppose that you need doing somethings when the WebRole start, well put your code in the WebRole.cs ;)
Here you can override OnStart() and OnStop() and put your code that wiil be execuded when the WebRole will start.
I've used this way to run a BakgroundWorker that do some scheduled tasks, independently from IIS.
I hope this help.
Davide.
Note:
1 - if you dont'have a WebRole.cs create it in the root of project and write inside:
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
...your code...
return base.OnStart();
}
}
2 - If you need to debug the code mind that you need to run VS in debug with the Azure project that refer to WebApp as a "Run Project", otherwise the WebRole will not be called
You could try putting some code in your WebRole.cs to request some URLs from your website. I've tried that, and it seems to work somewhat. But it's a pain to debug, so I never got it really nailed down.
Another option would be to use IIS Application Initialization. You can't use it on IIS 7.5, but you can get IIS 8 if you upgrade your roles to Windows 2012 (set osFamily="3" in your .cscfg).