How Can I Call To aspx page in Controller Class in asp.net
Loading
How Can I Call To aspx page in Controller Class in asp.net
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted May 17, 2023, 12:58 AM EDT
To call an ASPX page from a controller class in ASP.NET, you can use the `Redirect` or `RedirectToAction` method. Here's how you can do it:
1. In your controller class, import the `System.Web.Mvc` namespace.
using System.Web.Mvc;
2. Create an action method in your controller that will handle the request to navigate to the ASPX page.
public ActionResult RedirectToAspxPage()
{
return Redirect("~/Path/To/YourPage.aspx");
}
Replace `"~/Path/To/YourPage.aspx"` with the actual path to your ASPX page.
3. Alternatively, if you have a separate action method for the ASPX page, you can use the `RedirectToAction` method.
public ActionResult RedirectToAspxPage()
{
return RedirectToAction("YourActionMethod", "YourController");
}
Replace `"YourActionMethod"` and `"YourController"` with the actual names of your action method and controller that handle the ASPX page.
4. You can also pass parameters to the ASPX page by including them in the redirect URL.
public ActionResult RedirectToAspxPageWithParams()
{
string param1 = "value1";
string param2 = "value2";
return Redirect($"~/Path/To/YourPage.aspx?param1={param1}¶m2={param2}");
}
In this example, the values of `param1` and `param2` will be passed as query parameters to the ASPX page.
Make sure to replace `"~/Path/To/YourPage.aspx"` with the correct path to your ASPX page, and modify the action method and controller names as needed.
Jagapathibabu Banoth166 reputationPosted May 17, 2023, 8:32 AM EDT
>Not Working Sir......
Vishal JoshiRank #377 · 6.7K reputationPosted May 18, 2023, 8:24 AM EDT
Hello,
Use the Controller's Redirect() method. you need to pass the full path with the domain name to redirect or call the aspx page from controller. checkout below sample code.
public ActionResult YourAction() { // ... return Redirect("http://www.example.com" + "/path/yourpage.aspx"); }Thanks
Vishal
Deepak RawatRank #646 · 3.7K reputationPosted May 19, 2023, 1:06 AM EDT
To call an ASPX page from a controller class in ASP.NET, you can use the
Server.Transfer()method. This method transfers control from the current page or handler to the specified ASPX page while maintaining the original URL in the browserpublic ActionResult CallAspxPage() { // Perform any necessary processing or business logic here // Call the ASPX page Server.Transfer("~/YourPage.aspx"); // The code after Server.Transfer will not be executed since the control is transferred to the ASPX page // Return an empty result or redirect if needed return new EmptyResult(); }his example, the
CallAspxPage()method in your controller class is called when a specific action is triggered. You can add your own processing or business logic before calling the ASPX page.The
Server.Transfer("~/YourPage.aspx")statement transfers control to the specified ASPX page, which is represented by the tilde (~) and the relative path to your ASPX page. You need to provide the correct path to your ASPX page.After calling
Server.Transfer(), any code following this statement in the controller method will not be executed since control is transferred to the ASPX page. If you need to execute additional code or redirect after the transfer, you can place it before theServer.Transfer()statement.