VS2015 asmx method not found - asp.net

I am having legacy project which was migrated to visual studio 2015. Everything works well, only asmx action is not found.
I don't understand what is wrong here? My project runs inside IIS express.
I've tried to create virtual directory inside IIS and if I open website from IIS asmx works fine.
What I've also tried is to delete and then add .asmx file to project. Nothing changed.
Only within IIS express it doesn't work (when project is run directly from visual studio). Error message:
Failed to load resource: the server responded with a status of 404
(Not Found)
http://localhost:53358/wf/wsSearchCAMERC.asmx/GetBAUSERSearch1
Settings:
Code:
namespace fCatEve
{
/// <summary>
/// Summary description for wsSearchCAMERC
/// </summary>
[WebService(Namespace = "fCatEve")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class wsSearchCAMERC : System.Web.Services.WebService
{
[WebMethod]
public string[] GetBAUSERSearch1(string prefixText, int count, string contextKey)
{
// code omitted for clarity
}
}
}

I've solved the problem by copy-pasting methods from .asmx to MVC controller, which is asynchronous by default. I can now call those methods with same link as from .asmx.

Related

How can I open a web api URL from within Visual Studio

I have a feeling this is off topic as it's not about code but, it is something any one working in MVC and Visual Studio is likely going to find useful.
Is it possible to open a browser at the URL of the route I am working on within MVC or Web Api?
For example, if my Web Api looked like
[Route("api/[controller]")]
[ApiController]
public class MyApi : ControllerBase
{
[HttpGet]
[Route("GetItAll")]
public JsonResult Get()
{
return GetData();
}
}
I'd like to be able to, for example, right click in the Get function, and choose 'launch in browser'.
Then, Visual Studio would generate the URL (in this case .../api/MyApi/GetItAll), start debugging and navigate to this URL in the browser

Using HTTPS for api routes ASP.NET

I have a asp.net application in which I used HTTP controllers (ApiController) as below
[Route("api/dashboard/{id}")]
[HttpGet]
public DataTable getDashboardDetails(int ID)
{
}
Both my web application and controllers are within same application. We have modified our website from HTTP to HTTPS.
Now, when I try to call the above api route as
https://website.com/api/dashboard/123
it throws
404 - File or directory not found
Error
Please help to get the api called. Its working in localhost.
Have you checked the ISS and visual studio configuration ?
Sometimes it need to be restarted to get this changes.

Response Compression Middleware for ASP.NET Core ignored on Azure

i have a simple ASP.NET Core App and in the Startup.cs I added the Response Compression Middleware to get my responeses compressed by gzip - super easy.
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
app.UseStaticFiles();
app.UseMvc(routeBuilder =>
{
var defaults = new { controller = "Views", action = nameof(ViewsController.Index) };
routeBuilder.MapRoute("default", "{controller}/{action}/{id?}", defaults);
routeBuilder.MapSpaFallbackRoute("spa-fallback", defaults);
});
}
On my local maschine when I start the App out of Visual Studio regardless of whether IISExpress or Project Command my responses are compressed.
Now I publish my ASP.NET Core App to Azure with the Publish-Command from Visual Studio as an "Azure App Service" every think works just like local only the compression not.
Does anyone have an idea what i missed?
---UPDATE---
Ok, i created a empty .Net Core Web Application with Visual Studio. I edit the Startup.cs to look like this, and put a simple index.html in the wwwroot folder. Than i right click the project and choose the deploy option. I created a new profile with a new Resourcegroup, new Plan and a new AppService.
here is the result: http://gzipapptest.azurewebsites.net/index.html But chrome/fiddler show's no gzip - maybe it because of the company-proxy can u try the website?
Thanks, iBot
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
app.UseStaticFiles();
}
}
I test it with you mentioned code, it works correctly on my side. And it is very odd that you mentioned sceenshot that the remote address: 127.0.0.1:8888. If it is possible please have a try to create a new WebApp and deploy it.
Updated:
It also works in your WebApp, you could refer to the screen. If you don't see the gzip in the response header, I assume that it received from the cache.
Received from cache
I know this is an old question, however, if anyone else is having this issue and you are using the ASP.NET Core In-Process Hosting model on IIS, you must also install the Dynamic Content Compression feature in Server Manager --> Web Server --> Performance.

Access ASP.Net Data Cache from a Web API method in same ASP.Net project

I need to remove ASP.Net cache from inside a Web API method. This cache by the name of 'ContentNames' was set in the code-behind of an aspx page using following code. Is this possible, and if yes, then how would I access ASP.Net data cache from inside the Web API method?
The Web API and all the aspx pages are part of the same website project in Visual Studio 2013.
System.Web.HttpContext.Current.Cache.Insert("ContentNames", dt, null,
System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 60, 0));
The Web API method from where I need to access and remove 'ContentNames' data cache, looks like below.
[Authorize]
[HttpPut]
public HttpResponseMessage ApproveOrRejectContent( RadEditorContentAdminParas paras)
{
var data = GetUnApprovedContent(paras.ApprovedOrRejected, paras.PageId);
//NEED to remove a Cache by the name of 'ContentNames' ???
return Request.CreateResponse<ContentsInfoResult>(HttpStatusCode.OK, data);
}
Just add reference of System.Web to your Web Api controller and you be able to access Current cache and remove it:
System.Web.HttpContext.Current.Cache.Remove("ContentNames");

How to detect if the web application is deployed as a virtual directory?

My MVC3 Web Application is not always deployed as a site in IIS, so I need to detect if it has been deployed as a virtual directory or application in order to handle the path string.
for example, if the site is deployed as a website under IIS root, if i write:
\ABC\test.txt
this is fine, the request goes to http://somehost/ABC/test.txt
but if the site is deployed as a virtual directory or application under an existing site in IIS, for example:
http://somehost/mymvcapp/
then, the request for "\ABC\test.txt" will not be correct.
I understand that write "~\App_Data\test.txt" will solve the problem, but "~\" can only be processed by the server in current web context. Sometime I need to do some process on the file in other layers, they can't touch web context.
So I need to detect if the application has been deployed as a virtual directory. and find the actual physical path to the file. Is there any way to do it?
Found a way, but I am not sure it is nice:
check HttpRuntime.AppDomainAppVirtualPath == "/"
If your business layer can't reference System.Web, then you have to expect that it can't detect any information about your web application period. This means that the code should not be expected to resolve file paths within your site.
What you could do instead is have an intermediate configuration layer that the application initializes and the business layer can consume. For example, given this interface which is accessible to both layers:
public interface IConfiguration
{
string DataFolder { get; }
}
... you could have code in your Global.asax that initializes it:
IConfiguration config = ...;
...
config.DataFolder = this.Server.MapPath("~/App_Data");
Your business layer can now just read the configuration and form a path to the expected file:
var filePath = Path.Combine(this.configuration.DataFolder, "test.txt");

Resources