How to fix status code : 302 error

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi Folks,

I am developing plugin in Nop 3.90 version which is override to http://{domain}/admin "Admin Dashboard".
For this I followed below steps in plugin class library,
RouteProvider.cs

RemoveRoute(routes, "Admin");
            routes.MapRoute("Nop.Plugin.Varahi.VendorManagement.Admin",
                                          "Admin",
                                           new { controller = "Home", action = "Index", orderIds = UrlParameter.Optional, area = "Admin" },
                                           new[] { "Nop.Plugin.Varahi.VendorManagement.Controllers" });



HomeController.cs
 public ActionResult Index()
        {
return View("~/Plugins/Varahi.VendorManagement/Views/Verification/Index.cshtml", model);
}


Dashboard page design overwritten in above mentioned page.


Above routing is working fine when I run application locally and local IIS(version 10).

But when I deployed at live server this routing is not working as expected.
its throws exception "We're sorry, an internal error occurred. "
Status code : 302
Live server IIS version is 7.0


And also some other functionalities are not working like send email and captcha(version 2).

Please let me know where I did wrong.

Thanks in advance!
6 years ago
Hello,

Can you provide full stack of error from system log?

Thanks,
Jatin
6 years ago
[/b]forefront wrote:
Hello,

Can you provide full stack of error from system log?

Thanks,
Jatin


Below is function remove existing route,
    private void RemoveRoute(RouteCollection routes, string key)
        {

            var temp = routes[key];
            routes.Remove(temp);


        }



And below is log and exception message,
[b]An error occurred when trying to create a controller of type 'Nop.Admin.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.


below is the stackTrace

System.InvalidOperationException: An error occurred when trying to create a controller of type 'Nop.Admin.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
   --- End of inner exception stack trace ---
   at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
   at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
   at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
   at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.<>c__DisplayClass7.<BeginProcessRequest>b__6()
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
   at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
   at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
   at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)
   at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName)
   at ASP._Page_Administration_Views_Home_Index_cshtml.Execute() in e:\OTS SITES\GG\GadgetGuru.mobi\Administration\Views\Home\Index.cshtml:line 48
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.RunPage()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



Hope this will help you.
Let me know if anything else.
6 years ago
Post the constructor of your HomeController

Thanks,
Jatin
6 years ago
forefront wrote:
Post the constructor of your HomeController

Thanks,
Jatin


Please check below,

using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Vendors;
using Nop.Plugin.Varahi.VendorManagement.Domain;
using Nop.Plugin.Varahi.VendorManagement.Models;
using Nop.Plugin.Varahi.VendorManagement.Services;
using Nop.Services.Common;
using Nop.Services.Customers;
using Nop.Services.Media;
using Nop.Services.Vendors;
using Nop.Web.Framework.Controllers;
using System;
using System.Linq;
using System.Web.Mvc;

namespace Nop.Plugin.Varahi.VendorManagement.Controllers
{
    public class HomeController : BasePluginController
    {
        #region Fields
                                              
        private readonly ICustomerService _customerService;        
        private readonly IWorkContext _workContext;
        private readonly ICacheManager _cacheManager;        
        private readonly IVendorService _vendorService;                        
        private readonly IPictureService _pictureService;        
        private readonly VendorSettings _vendorSettings;        
        private readonly IAddressService _addressService;                
        private readonly IBusinessDetailService _businessDetailService;

        #endregion

        #region Ctor

        public HomeController(
            ICustomerService customerService,            
            IWorkContext workContext,
            ICacheManager cacheManager,            
        IVendorService vendorService,        
        IPictureService pictureService,        
        VendorSettings vendorSettings,        
        IAddressService addressService,                
        IBusinessDetailService businessDetailService)
        {            
            this._customerService = customerService;
            this._workContext = workContext;
            this._cacheManager = cacheManager;
            this._vendorService = vendorService;
            this._pictureService = pictureService;
            this._vendorSettings = vendorSettings;
            this._addressService = addressService;
            this._businessDetailService = businessDetailService;
        }

        #endregion

        public ActionResult Index()
        {
            var dashboardModel = new DashboardModel();
            dashboardModel.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            if (dashboardModel.IsLoggedInAsVendor)
            {
                VendorInfoModel model = new VendorInfoModel();

                    return View("~/Plugins/Varahi.VendorManagement/Views/Verification/Index.cshtml", model);

            }

            return View("~/Administration/Views/Home/Index.cshtml");
        }
  }
}



Here I have created new service as BusinessDetailService, which has resolved in DependancyRegistar file

using Autofac;
using Autofac.Core;
using Nop.Core.Configuration;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Varahi.VendorManagement.Data;
using Nop.Plugin.Varahi.VendorManagement.Domain;
using Nop.Plugin.Varahi.VendorManagement.Factories;
using Nop.Plugin.Varahi.VendorManagement.Services;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.Varahi.VendorManagement
{
    /// <summary>
    /// Dependency registrar
    /// </summary>
    public class DependencyRegistrar : IDependencyRegistrar
    {
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            builder.RegisterType<BusinessDetailService>().As<IBusinessDetailService>().InstancePerLifetimeScope();
            builder.RegisterType<VendorBusinessFactory>().As<IVendorBusinessFactory>().InstancePerLifetimeScope();

            //data context
            this.RegisterPluginDataContext<VendorManagementObjectContext>(builder, "nop_object_context_vendor_management");

            //override required repository with our custom context
            builder.RegisterType<EfRepository<BusinessDetail>>()
                .As<IRepository<BusinessDetail>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_vendor_management"))
                .InstancePerLifetimeScope();
        }

        /// <summary>
        /// Order of this dependency registrar implementation
        /// </summary>
        public int Order
        {
            get { return 1; }
        }
    }
}



Please check above.

I just want to know, Is is correct which I followed steps for overriding /admin action in plugin?
6 years ago
Seems your constructor and dependency is fine. But this error came when service is not define properly in constructor or dependency

You can also modify your route.

It should Not require to remove existing route. Just put priority high and check

Thanks,
Jatin
6 years ago
forefront wrote:
Seems your constructor and dependency is fine. But this error came when service is not define properly in constructor or dependency

You can also modify your route.

It should Not require to remove existing route. Just put priority high and check

Thanks,
Jatin


Thanks Jatin you saved my time.
Remove existing route, it is necessary otherwise error throws "given route key already exist".

I kept remove and add route code, just I put priority high as 100.
Its works for me.

Thanks once again!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.