unable to delete directory from SFTP server

I am trying to delete the directory from my SFTP server. I am using EnterpriseDT.Net.Ftp SSHSCPClient for connecting to the server with private key, no password.

When I use the

SSHSCPClient ftpConnection;

//Successfully connected and able to upload the files but

ftpConnection.MultipleDeleteDirectories(remoteFolder);

it throws the error

[Message = "This operation is not currently supported."]

Render View to String caching issue

For my project I currently implemented a ViewRender for my asp.net core application. It generates Views without a controller to html, this works fine using the following code:

public class ViewRenderService : IViewRenderService
{
    private readonly IRazorViewEngine _razorViewEngine;
    private readonly ITempDataProvider _tempDataProvider;
    private readonly IServiceProvider _serviceProvider;

    public ViewRenderService(IRazorViewEngine razorViewEngine,
        ITempDataProvider tempDataProvider,
        IServiceProvider serviceProvider)
    {
        _razorViewEngine = razorViewEngine;
        _tempDataProvider = tempDataProvider;
        _serviceProvider = serviceProvider;
    }

    public async Task<string> RenderToStringAsync(string viewName, object model)
    {
        var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };

        var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
        string viewgerendered = "";
        try
        {
            using (var sw = new StringWriter())
            {
                var viewResult = _razorViewEngine.GetView(viewName, viewName, false);

                if (viewResult.View == null)
                {
                    throw new ArgumentNullException($"{viewName} does not match any available view");
                }

                var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
                {
                    Model = model
                };        

                var viewContext = new ViewContext(
                    actionContext,
                    viewResult.View,
                    viewDictionary,
                    new TempDataDictionary(actionContext.HttpContext, _tempDataProvider),
                    sw,
                    new HtmlHelperOptions()
                );

                await viewResult.View.RenderAsync(viewContext);

                viewgerendered = sw.ToString();
                return viewgerendered;
            }
        }
        catch (Exception e)
        {
            object temp = e.Message + " - " + e.StackTrace;
            return temp.ToString();
        }
    }

    public Task RenderToStringAsync(string v)
    {
        throw new NotImplementedException();
    }
}

Source: https://ppolyzos.com/2016/09/09/asp-net-core-render-view-to-string/

Changes which are made to views which use this renderer are not updated without restarting the application itself. Diving further into it, the views are cached. A comment within the source mentions using the _razorViewEngine.GetView method should get rid of my caching issue. However this doesn’t work.

What I got, trying to figure out a way to register a new ViewRender, with a slight modification of the ViewRenderService.

//Seems not to be available on asp.net core 2.0...
services.AddMvc().Configure<MvcViewOptions>(options =>
            {
                options.ViewEngines.Clear();
                options.ViewEngines.Add(typeof(CustomViewEngine));
            });

And to overload the RazorViewEngine to expose the ViewLookupCache, where supposedly the view cache is located.

  public class CustomViewEngine : RazorViewEngine
    {
        public CustomViewEngine(
            IRazorPageFactoryProvider pageFactory, 
            IRazorPageActivator pageActivator,
            HtmlEncoder htmlEncoder, 
            IOptions<RazorViewEngineOptions> optionsAccessor, 
            Microsoft.AspNetCore.Razor.Language.RazorProject razorProject, 
            ILoggerFactory loggerFactory, 
            System.Diagnostics.DiagnosticSource diagnosticSource) : 
            base(pageFactory, pageActivator, htmlEncoder, optionsAccessor,razorProject,loggerFactory, diagnosticSource){ }

        public void RemoveCachedView(string view)
        { 
            this.ViewLookupCache.Remove(view);
        }
    }

There’s not a lot to find on how caching is done within asp.net core 2.0 for views and clearing a particular view / set of. Basically I want to find a way how I can flush an entire selection of cached views as a command, for performance reasons.

Namespace from other projects not available

I have a solution with 4 projects with these namespaces:

project name TPCO

namespace TPCO
namespace TPCO.Controllers
namespace TPCO.Models

project name TPCO.Core

namespace TPCO.Core.Data
namespace TPCO.Core.Domain
namespace TPCO.Core.Models

project name TPCO.Data

namespace TPCO.Data

project name TPCO.Tests

namespace TPCO.Tests.Controllers

The TPCO.Core and TPCO.Data projects were originally part of an ASP.Net Web Application. I imported them into an ASP.Net MVC5 application solution containing the TPCO and TPCO.Test projects.

For some reason, I cannot see any of the namespaces from TPCO.Core or TPCO.Data from TPCO. I also cannot see TPCO, TPCO.Controllers or TPCO.Models from TPCO.Core or TPCO.Data projects. However, I can see TPCO.Core.* from TPCO.Data and vice versa.

And from TPCO.Tests, I can only see the namespaces from the TPCO and TPCO.Tests projects.

All projects have same target framework, per: Namespace not available in other project
Also, ALL classes in TPCO.Core and TPCO.Data are marked public

What is going on and how do I remedy this? Could it be that the TPCO.Core and TPCO.Data projects reside outside the folder structure of the MVC app that is causing this?

MVC page view how to display the .htm content [on hold]

In my old system I have a .aspx page which will allow the user to enter their zip code and when they hit search, the request send to third party. They will send the response as a .htm page and we just binded the result in our web page through here is the syntax which we used it in our .aspx page.

<asp:Content ID="Content1" ContentPlaceHolderID="CPHC" runat="server">    
<h1>    
My zipcode    
</h1>    
<table cellpadding="0" cellspacing="0" width="100%">    
<tr><td style="border:solid 0px red; margin:0px; padding:0px;"><iframe width="100%" height="800px" src='https://www.Mywebsite/zipcode/bmi.htm' scrolling="no" frameborder="0"></iframe></td></tr>    
</table>    
</asp:Content>       

My goal is to bind the same .htm content response into my MVC page view.

Can I implement the same iframe logic to bind the .htm page into my view?

Which is the best solution to achieve this? Can anyone help me with this?

ASP.Net MVC: Should I hash or encrypt route and query string data?

My programming knowledge is not very good. So here I discussed query string and route data security. Please review my approach and tell me am I thinking right way.

Often we work with query string and route data pass to controller action. So user can edit those data. For security purpose I do not allow to user edit route and query string data.

So I thought i will create a hash using those query string and route data and append that hash to end of URL.

  1. Is my thinking correct?
  2. Should I hash or encrypt query string and route data?
  3. Which one will be best…hashing or encrypt query string and route data?

This is the way I am doing it now. Here is bit code snippet:

@Html.ActionLink("Test", "Index", new { page = 1, q = Utility.HashData("Hello") })

public static class Utility
{
    public static string HashData(string input)
    {
        string retdata="";
        string salykey = "!xcorb@sinon_";
        byte[] inputBytes = Encoding.UTF8.GetBytes(string.Concat(input, salykey));
        SHA512Managed sha512 = new SHA512Managed();

        byte[] outputBytes = sha512.ComputeHash(inputBytes);
        string b64 = Convert.ToBase64String(outputBytes);
        b64 = b64.Replace('+', '-');
        retdata = b64.Replace('/', '_');
        return retdata;
    }
}

I am hashing data hello and now URL look like http://localhost:61151/Home/Index/1?q=NhX4DJ0pPtdAJof5SyLVjlKbjMeRb4-sf933-9WvTPd309eVp6AKFr9-fz-5Vh7puq5IDan-ehh2nnGIawPzFQ%3D%3D

Is it ok?

I just hash Hello and now see how big hash has been generated. So when I will hash many query string and route data together then my hash data will be huge. So if it will be huge that may cause an issue because the URL length must has some limitation….am I right?

  1. Can I shorten hashing data length? If possible then which hashing algorithm I should use?

Please discuss my points and drive me to right direction. Thanks.

How to bind multiple dropdown in edit mode [on hold]

I am using MVC in which io am trying to bind a multi Select drop down in Edit mode.I am passing multiple value as in string array as well in list into the view bag.

View code

<div class="col-md-8">
    @Html.DropDownListFor(s => s.Size, (MultiSelectList)ViewBag.AllSize, "Select", new { @class = "form-control select2Size", style = "width:100%;", multiple = "multiple" })
    @Html.ValidationMessageFor(s => s.Size)
</div>

Controller code

public ActionResult EditPatternSize()
{
    try
    {
        if (Session["PatternSelectorIDAdmin"] != null)
        {
            int PatternSelectorID = Convert.ToInt32(Session["PatternSelectorIDAdmin"]);
            _adminRepo = new AdminRepo();
            var PatternSelector = _adminRepo.GetPatternSelectorById(PatternSelectorID);
            PatternSelector.Size = PatternSelector.MultipleSize.Split(',');
            PatternSelector.test = PatternSelector.Size.OfType<string>().ToList();
            dynamic AllTileType = _adminRepo.GetMasterDataByMasterID(HelperConstant.GetMasterDataID(MasterConstant.TileProject));
            ViewBag.AllTileType = new SelectList(AllTileType, "ID", "MasterData");

            dynamic AllSize = _adminRepo.GetMasterDataByMasterID(HelperConstant.GetMasterDataID(MasterConstant.Size));
            ViewBag.AllSize = new MultiSelectList(AllSize, "MasterData", "MasterData", PatternSelector.test);
            return View(PatternSelector);
        }
        else
        {
            return RedirectToAction("PatternSelector", "Admin");
        }
    }
    catch (Exception)
    {

        throw;
    }
}

Pagination Show and Hide Rows in View based on Index

In MVC application, I am fetching rows on demand and enabled pagination. If Pagination is navigated on sequence (1,2,3 etc.) it is working fine.

But when it is navigated non-sequence (i.e) after successful 1st load and being on the first page, if I directly navigate to Page3, the page shows empty.

This is because I am using Table.Rows.Slice(startIndex, endIndex) to show and hide rows based on PageSize.

So When I click the 3rd page, rows will be fetched from server and its row index will be from 11 to 20 (considering pagesize 10). But page3 will show rows from 21-30 where actually table has no rows. Table has only 20 rows in this scenario as actually Page1 and Page3 alone clicked.

Any Ideas to handle this scenario?

Page1: 1-10 Table Rows - Real Data   Table1.slice(1,10)
Page2: Not clicked
Page3: 11-20 Table Rows - Real Data  Table1.slice(21,30)

Just looking for some logical idea.

If I open modal,background other empty modal is coming in asp .net

I am trying to open modal in .net MVC,but it showing two modal.I dont know how those two are coming.because of this it is not considering built in class.please help me to solve this issue. Some one are saying this is the default behaviour in asp is that true?

enter image description here

cshtml code what i have written in cshtml file :

    <input type="button" id="myBtn" class="btn btn-warning" data-toggle="modal" data-target="#myModall" value="Add Job Item" />

     *on click this open below modal*

here modal-lg is not working because of this i have to use custom class.

    <div class="modal fade" id="myModall" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>This is a small modal.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    *js*

    $("#myBtn").click(function () {
                 $('#myModal').html(data);
                    $('#myModal').modal('show');
            });

asked many they are setting front modal as like background modal,is that correct?If not,what is the solution to solve this.from two days I am trying to solve,not able to find from where parent modal coming.

How to create js using objects from Controller

In my actual task i need to create graph for app based on ASP.NET MVC.
I found suitable js, but I forced a problem how to create js object from values, wich created in controller.
For example:

public class User
{
    public string Name { get; set; }
    public string Group { get; set; }
}
   public ActionResult Index()
    {
        List<User> users = new List<User>()
        {
            new User{Name = "Boss", Group = "Boss"},
            new User{Name = "Emp 1", Group = "Emps"},
            new User{Name = "Emp 2", Group = "Emps"},
            new User{Name = "Emp 3", Group = "Emps"},
            new User{Name = "Emp 4", Group = "Emps"},
        };
        ViewBag.Users = users;
        return View();
    }

I have collection of User in my controller.
Below js code, wich I need to create

var nodes = [
    { "name": "Boss", "group": "Boss" },
    { "name": "Emp 1", "group": "Emps" },
    { "name": "Emp 2", "group": "Emps" },
    { "name": "Emp 3", "group": "Emps" },
    { "name": "Emp 4", "group": "Emps" },
];

I want to now could I create js code like

var nodes = function () {
        var array = [];
        for (var i = 0; i < @ViewBag.Users.Count; i++) {
            array.push({"name": @ViewBag.Users[i].Name, "group": @ViewBag.Users[i].Group})
        }
        return array;
    };

P.S. This code not working because of i not exist.